<?php
class ServiceController extends Controller
{
	public function actionService()
	{
		$requestType = Yii::app()->request->requestType;
		$params = $_REQUEST;
		switch($requestType){
			case 'GET':
				$serviceMethod = 'service'.ucfirst(strtolower($requestType));
				if(method_exists($this, $serviceMethod)){
					$this->$serviceMethod();
				}
				break;
			case 'POST':
				$serviceMethod = 'serviceCreate';
				$data = Utils::decodeBackboneData ();
				if(method_exists($this, $serviceMethod)){
					$this->$serviceMethod($data);
				}
				break;
			case 'DELETE':
				$serviceMethod = 'service'.ucfirst(strtolower($requestType));
				$id = key($params);
				if(method_exists($this, $serviceMethod)){
					$this->$serviceMethod($id);
				}
				break;
			case 'PUT':
				$serviceMethod = 'serviceUpdate';
				$keys = array_keys($params);
				$id =  end($keys);
				array_pop($params);
				$data = Utils::decodeBackboneData ();
				if(method_exists($this, $serviceMethod)){
					$this->$serviceMethod($id,$data);
				}
				break;
		}
	}
}